﻿using Castle.Core.Logging;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace WebAppHappyNewYear.Filter
{
    public class CustomActionFilterAttribute : Attribute, IActionFilter, IFilterMetadata,IOrderedFilter
    {
        private readonly ILogger<CustomActionFilterAttribute> _logger;

        public CustomActionFilterAttribute(ILogger<CustomActionFilterAttribute> logger)
        {
            _logger = logger;
        }

        public int Order { get; set; }

        public void OnActionExecuted(ActionExecutedContext context)
        {
            Console.WriteLine($"{nameof(CustomActionFilterAttribute)} {context.HttpContext.Request} OnActionExecuted ");
            _logger.LogInformation("OnActionExecuted");

        }

        public void OnActionExecuting(ActionExecutingContext context)
        {
            Console.WriteLine($"{nameof(CustomActionFilterAttribute)} {context.HttpContext.Request} OnActionExecuting ");
            _logger.LogInformation("OnActionExecuting");
        }
    }

    public class CustomActionActionFilterAttribute : Attribute, IActionFilter, IFilterMetadata
    {
        
        public void OnActionExecuted(ActionExecutedContext context)
        {
            Console.WriteLine($"{nameof(CustomActionActionFilterAttribute)} {context.HttpContext.Request} OnActionExecuted ");

        }

        public void OnActionExecuting(ActionExecutingContext context)
        {
            Console.WriteLine($"{nameof(CustomActionActionFilterAttribute)} {context.HttpContext.Request} OnActionExecuting ");
        }
    }

    public class CustomControllerActionFilterAttribute : Attribute, IActionFilter, IFilterMetadata
    {

        public void OnActionExecuted(ActionExecutedContext context)
        {
            Console.WriteLine($"{nameof(CustomControllerActionFilterAttribute)} {context.HttpContext.Request} OnActionExecuted ");

        }

        public void OnActionExecuting(ActionExecutingContext context)
        {
            Console.WriteLine($"{nameof(CustomControllerActionFilterAttribute)} {context.HttpContext.Request} OnActionExecuting ");
        }
    }

    public class CustomGlobalActionFilterAttribute : Attribute, IActionFilter, IFilterMetadata
    {

        public void OnActionExecuted(ActionExecutedContext context)
        {
            Console.WriteLine($"{nameof(CustomGlobalActionFilterAttribute)} {context.HttpContext.Request} OnActionExecuted ");

        }

        public void OnActionExecuting(ActionExecutingContext context)
        {
            Console.WriteLine($"{nameof(CustomGlobalActionFilterAttribute)} {context.HttpContext.Request} OnActionExecuting ");
        }
    }
}
